class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int prices_min = INT_MAX, ret = 0;
        for (auto& price: prices) {
            ret = max(ret, price - prices_min);
            prices_min = min(prices_min, price); 
        }

        return ret;
    }
};